#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: node_base.py 
@version:
@time: 2022/03/10 
"""
import uuid


class NodeBase:

    @property
    def newId(self):
        return str(uuid.uuid4())

    @staticmethod
    def clone_svg(database_type):
        if database_type == 'kafka':
            database_type = 'Kafka'
        if database_type == 'postgres':
            database_type = 'pg'
        if database_type == 'db2':
            database_type = 'DB2'
        return f'{database_type}.svg'

    @staticmethod
    def sync_type(database_type):
        if database_type in [
            'redis', 'gridfs', 'dummy db', 'elasticsearch', 'custom_connection',
            "xml", "excel", "csv", "json",
            "kafka", "mq", "hbase", "hive", "tcp_udp",
            "hana", "dameng", "clickhouse", "adb_mysql", "doris"
        ]:
            return database_type
        if database_type == 'mongodb':
            return 'collection'
        if database_type == 'vika':
            return 'Vika'
        return 'table'

    @staticmethod
    def get_connection_id_by_name(name):
        from TapClientCore.T05_TM_feature.v1.TMF01_datasource.tmf_datasource import TMFDataSource
        return TMFDataSource().query_datasource_by_name(name).get('id')

    @staticmethod
    def get_table_id_by_source_and_name(source_id, table_name):
        from TapClientCore.T02_tm_api.v1_api.v1_api_module.v1api03_metadata import V1MetaData
        _filter = {"where": {
            "source.id": source_id,
            "original_name": table_name,
            "is_deleted": False
        }}
        return V1MetaData().get_metadata_by_filter(_filter).get('data')[0].get('id')


if __name__ == '__main__':
    T = NodeBase()
    res = T.get_table_id_by_source_and_name('62820971a2a44b1599ba6fdf', 'AA')
    print(res)
